package com.example.demo5.demo5.test;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController //响应http请求，Spring Boot会自动将其对象注入框架
public class helloWorld {
    @GetMapping("/hello")   //响应http get请求，/hello为匹配的url(接口）
    public String hello(){
        return "Hello Spring Boot:"+ nameAges.toString();
    }
    private static HashMap<String,Integer> nameAges = new HashMap<>();

    @PostMapping("/hello")
    public String helloPost(String name,int age){
        nameAges.put(name,age);
        return "add name:"+name+",age"+age;
    }

    @PutMapping("/hello")
    public String helloPut(String name,int age){
        nameAges.replace(name,age);
        return "update name:"+name+",age="+age;
    }

    @DeleteMapping("/hello/{name}")
    public String helloDel(@PathVariable String name){
        nameAges.remove(name);
        return "delete name:"+ name;
    }

}
